package com.ymatou.iapi.liveseller.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.UpdateLiveInfoBean;
import com.ymatou.iapi.liveseller.service.UpdateLiveInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*修改直播信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateLiveInfo{
	private static UpdateLiveInfoBean updateliveinfoBean;
	private static UpdateLiveInfoCall updateliveinfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改直播信息");
	}

	@Before
	public void caseUp() {
		updateliveinfoBean=new UpdateLiveInfoBean();
		updateliveinfoCall=new UpdateLiveInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateliveinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(LiveRoom livedto, UpdateLiveInfoBean UpdateLiveInfoBean2) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive =new LiveRoomWapper().selectLiveRoomById(livedto.getId());
		Logger.verifyEquals(UpdateLiveInfoBean2.getLiveCategoryId(), dblive.getLiveCategoryId(), "验证LiveCategoryId");
		Logger.verifyEquals(UpdateLiveInfoBean2.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(UpdateLiveInfoBean2.getLiveDesc(), dblive.getLiveDesc(), "验证LiveDesc");
		Logger.verifyEquals(UpdateLiveInfoBean2.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateLiveInfo_001() {
		Logger.start(true,"修改直播信息,成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			updateliveinfoBean.setLiveId(livedto.getId());
			updateliveinfoBean.setLiveCategoryId(livedto.getLiveCategoryId()+1);
			updateliveinfoBean.setLiveCover(livedto.getLiveCover()+1);
			updateliveinfoBean.setLiveDesc(livedto.getLiveDesc()+1);
			updateliveinfoBean.setLiveTitle(livedto.getLiveTitle()+1);
			updateliveinfoBean.setOperator("autotest");
			updateliveinfoCall.setData(updateliveinfoBean);
			updateliveinfoCall.callService();			
			Logger.verifyEquals("200", updateliveinfoCall.getString("Code"), "验证code");
			verifyDB(livedto, updateliveinfoBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateLiveInfo_002() {
		Logger.start(true,"重复修改直播信息,成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			updateliveinfoBean.setLiveId(livedto.getId());
			updateliveinfoBean.setLiveCategoryId(livedto.getLiveCategoryId()+1);
			updateliveinfoBean.setLiveCover(livedto.getLiveCover()+1);
			updateliveinfoBean.setLiveDesc(livedto.getLiveDesc()+1);
			updateliveinfoBean.setLiveTitle(livedto.getLiveTitle()+1);
			updateliveinfoBean.setOperator("autotest");
			updateliveinfoCall.setData(updateliveinfoBean);
			updateliveinfoCall.callService();			
			Logger.verifyEquals("200", updateliveinfoCall.getString("Code"), "验证code");
			verifyDB(livedto, updateliveinfoBean);
			updateliveinfoBean.setLiveTitle(livedto.getLiveTitle()+2);
			updateliveinfoCall.callService();			
			Logger.verifyEquals("200", updateliveinfoCall.getString("Code"), "验证code");
			verifyDB(livedto, updateliveinfoBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateLiveInfo_003() {
		Logger.start(true,"不输入liveid失败");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			updateliveinfoBean.setLiveCategoryId(livedto.getLiveCategoryId()+1);
			updateliveinfoBean.setLiveCover(livedto.getLiveCover()+1);
			updateliveinfoBean.setLiveDesc(livedto.getLiveDesc()+1);
			updateliveinfoBean.setLiveTitle(livedto.getLiveTitle()+1);
			updateliveinfoBean.setOperator("autotest");
			updateliveinfoCall.setData(updateliveinfoBean);
			updateliveinfoCall.callService();			
			Logger.verifyEquals("400", updateliveinfoCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}